<template>
	<view class="c-tabbar-box">
		<view class="c-tabbar">
			<view class="tab-item" :class="{pitch:i ==tabbarIndex}" v-for="(v,i) in tabbarList" :key="i"
				@click="changeIndex(v,i)">
				<image :src="(i ==tabbarIndex?v.selectedIconPath : v.iconPath) | imgFilter" mode=""></image>
				<text>{{v.text}}</text>
			</view>
		</view>
		<view class="placeholder-box">
		</view>
	</view>

</template>
<script>
	export default {
		props: {
			list: {
				//openType： navigate|redirect|switchTab|reLaunch|navigateBack|exit
				type: Array,
				default: () => [{
						"pagePath": "/pages/index/index",
						"iconPath": "/static/img-tabbar/home.png",
						"selectedIconPath": "/static/img-tabbar/home-pitch.png",
						"openType": "switchTab",
						"text": "首页",
						s:"收到反馈"
					},
					{
						"pagePath": "/pages/mine",
						"iconPath": "/static/img-tabbar/mine.png",
						"selectedIconPath": "/static/img-tabbar/mine-pitch.png",
						"openType": "switchTab",
						"text": "我的"
					}
				]
			}
		},
		data() {
			let imgMap =new Map()
			imgMap.set('/pages/goods',{
				"iconPath": "/static/img-tabbar/mine.png",
				"selectedIconPath": "/static/img-tabbar/mine-pitch.png",
			})
			return {
				imgMap
			}
		},
		created() {
			console.log(this.imgMap,'----')
		},
		computed: {
			tabbarList: {
				get() {
					console.log(this.$store.state,'this.$store.state.setting.tabbarList')
					return this.$store.state.setting.tabbarList
					// return this.list
				}
			},
			tabbarIndex: {
				get() {
					return this.$store.state.tabbarIndex || 0
				},
				set(val) {
					this.$store.state.tabbarIndex = val
				}
			}
		},
		methods: {
			changeIndex(v, i) {
				let spik = {
					navigate: uni.navigateTo,
					redirect: uni.redirectTo,
					switchTab: uni.switchTab,
					reLaunch: uni.reLaunch,
					navigateBack: uni.navigateBack,
					exit: uni.exitMiniProgram
				}
				this.tabbarIndex = i
				spik[v.openType || 'switchTab']({
					url: v.pagePath
				})
				this.$vuex('pagsParams', v)
			}
		}

	}
</script>

<style lang="scss" scoped>
	.c-tabbar-box {}

	.c-tabbar {
		box-shadow: 1px 1px 5px 0px $uni-color-main;
		width: 100%;
		height: calc(90rpx + constant(safe-area-inset-bottom));
		height: calc(90rpx + env(safe-area-inset-bottom));
		display: flex;
		justify-content: space-around;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #fff;
		padding-top: 10rpx;

		.tab-item {
			flex: 1;
			display: flex;
			align-items: center;
			flex-direction: column;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-bottom: 5rpx;
			}
		}
	}

	.placeholder-box {
		height: calc( constant(safe-area-inset-bottom));
		height: calc( env(safe-area-inset-bottom));
	}
</style>